Characters and Strings

Characters


In [129]:
char1 = 'h'


Out[129]:
'h'

In [130]:
#Convertion

char2 = 'a'
typeof(Int(char2))


Out[130]:
Int64

Strings


In [131]:
str = "Domo arigato "
str2 = "Mr. Roboto"
str3 = str * str2
println(str3)
#Indexing
println(str[3])
println(str3[end])
println(str3[end-1])
println(str3[11:14])


Domo arigato Mr. Roboto
m
o
t
to M

String Interpolation


In [132]:
greet = "Hello"
whom = "world"
print(string(greet, ", ", whom, ".\n"))
#Another way to do the above 
println("$greet, $whom")
#interpolating expresions into strings
println("1 + 2 = $(1 + 2)")
#if you want to use the liteal symbol $ you can use a backslash
"Y mis \$50,000 pesos que?"


Hello, world.
Hello, world
1 + 2 = 3
Out[132]:
"Y mis \$50,000 pesos que?"

Common Operations


In [133]:
println("brain" == "drain")
println("gin" < "tequila")
println("Hello, world." != "Goodbye, world.")
println("1 + 2 = 3" == "1 + 2 = $(1 + 2)")

#You can check where a certain character is in a string
println(search("Pterodactyl",'y'))
println(search("Pterodactyl",'z'))

#You can use contain to check if a string is whithin another string
println(contains("Hello, world.", "world"))


false
true
true
true
10
0
true

Regular Expressions


In [134]:
x = r"^\s*(?:#|$)"

typeof(x)


Out[134]:
Regex

In [ ]: